import pymysql

def main():
    #创建连接对象
    conn=pymysql.connect(host='120.24.84.91',port=3306,
                         user='root',password='123456',
                         db='school',charset='utf8')
    # name=input('请输入名字：')
    # cid=input('请输入编号：')

    try:
        #获得游标对象
        with conn.cursor() as cursor:  #上下文语法，执行完会自动关
            #执行SQL命令得到结果
            cursor.execute('select colid, colname,website from tb_colleage ')
            # print(cursor.fetchall())
            for row in cursor.fetchall():
                print(f'学校编号：{row[0]}')
                print(f'学院名称：{row[1]}')
                print(f'学院网站：{row[2]}')
                print('*'*20)
            #操作成功执行提交
            conn.commit()
    except pymysql.MySQLError as error:
        print(error)
    finally:
        #关闭连接释放资源
        conn.close()

    # print(conn)


if __name__ == '__main__':
    main()